package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insertDish(Dish dish);

    /**
     * 插入菜品口味
     * @param dishFlavor
     */
    void insertDishFlavor(List<DishFlavor> dishFlavor);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     */
    Page<DishVO> search(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 删除批量菜品和口味
     * @param ids
     */
    void deleteById(List<Long> ids);
    void deleteDishFlavorByDishId(List<Long> ids);

    /**
     * 根据id查询菜品和口味
     * @param id
     */
    DishVO getById(Long id);

    @Select("select * from dish_flavor where dish_id = #{dishId}")
    List<DishFlavor> getByDishId(Long dishId);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 根据分类查询菜品
     * @param dish
     */
    List<Dish> list(Dish dish);

    /**
     * 根据套餐id查找菜品
     * @param setmealId
     * @return
     */
    @Select("select d.* from dish d left join setmeal_dish s on s.dish_id = d.id where s.setmeal_id = #{setmealId}")
    List<Dish> getDishBySetmealId(Long setmealId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
